package tech.aistar.mapper.trading;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.entity.trading.Goods;

import java.util.List;

/**
 * @author Ace
 * @version 1.0
 * @descriiption:本类用来演示:商品接口
 * @date 2019/9/27 0027.
 */
public interface GoodsMapper {

    /**
     * 添加商品
     */
    @Insert("insert into goods(goods_name,goods_type_id,user_id,avatar_images,degree,price,goods_details," +
            "goods_picture,praise,browse,place,way_to_trade,realname_status,credit_status)" +
            "values(#{goodsName},#{goodsTypeId},#{userId},#{avatarImages},#{degree},#{price},#{goodsDetails}," +
            "#{goodsPicture},#{praise},#{browse},#{place},#{wayToTrade},#{realnameStatus},#{creditStatus})")
    void save(Goods goods);

    /**
     * 删----通过设置status的值达到删除某个数据,不用真的删除
     * @param id
     */
    @Update("update goods set status=1 where id=#{value}")
    void delById(Integer id);

    /**
     * 查----查所有
     */
    @Select("select *from goods")
    List<Goods> findAll();
    /**
     * 查--根据id查
     */
    @Select("select *from goods where id=#{value}")
    Goods findById(Integer id);

    /**
     * 类型+商品简介
     * 如果条件不存在,则查询所有的
     * 多条件组合查询...一句写不完,所以弄个PhoneMapper.xml
     * 进行模糊查询
     */
        List<Goods> findAllLike(@Param("goodsDetails") String goodsDetails,@Param("goodsTypeId") Integer goodsTypeId);

    /**
     * 改--修改商品信息
     */
    @Update("update goods set goods_name=#{goodsName},goods_type_id=#{goodsTypeId},degree=#{degree},price=#{price},goods_details=#{goodsDetails}," +
            "goods_picture=#{goodsPicture},praise=#{praise},browse=#{browse},place=#{place},way_to_trade=#{wayToTrade},realname_status=#{realnameStatus}," +
            "credit_status=#{creditStatus},status=#{status} where id=#{id}")
    void Update(Goods goods);
}

